#include "cachedimageprovider.h"

CachedImageProvider::CachedImageProvider() :
    QQuickImageProvider(QQuickImageProvider::Pixmap)
{
}

QPixmap CachedImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
    Q_UNUSED(requestedSize)
    if (mCache.contains(id)) {
        QPixmap pix = mCache[id];
        if (size)
            *size = pix.size();
        return pix;
    } else {
        if (size)
            *size = QSize(0, 0);
        return QPixmap();
    }
}

void CachedImageProvider::cache(const QStringList &pixmaps)
{
    foreach(QString pix, pixmaps)
        if (!mCache.contains(pix))
            mCache.insert(pix, QPixmap(pix));
}

void CachedImageProvider::remove(const QString &pix)
{
    mCache.remove(pix);
}

void CachedImageProvider::add(const QString &pix)
{
    if (!mCache.contains(pix))
        mCache.insert(pix, QPixmap(pix));
}
